﻿using Microsoft.AspNetCore.SignalR.Client;
using Volo.Abp.DependencyInjection;

namespace FlyingEye.SignalRServices
{
    public class MonitorTaskCompletedResult
    {
        /// <summary>
        /// json序列化反序列化需要无参构造函数
        /// </summary>
#pragma warning disable CS8618 // 在退出构造函数时，不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
        private MonitorTaskCompletedResult()
#pragma warning restore CS8618 // 在退出构造函数时，不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
        {

        }

        /// <summary>
        /// 任务ID
        /// </summary>
        public string MonitorTaskId { get; set; }

        public string Value { get; set; }

        public MonitorTaskCompletedResult(string taskId, string value)
        {
            MonitorTaskId = taskId;
            Value = value;
        }
    }

    public class DeviceMaintenanceClientService : ITransientDependency
    {
        private readonly SignalRClientManager _manager;

        private HubConnection? _connection;

        public DeviceMaintenanceClientService(SignalRClientManager manager)
        {
            _manager = manager;
        }

        public async void SetListening()
        {
            _connection = await _manager.CreateAsync();

            _connection.On<MonitorTaskCompletedResult>("OnMonitorTaskCompletedAsync", OnMonitorTaskCompletedAsync);
        }

        private void OnMonitorTaskCompletedAsync(MonitorTaskCompletedResult result)
        {
            if (result.MonitorTaskId == "")
            {
                var value = result.Value;
                // to do
            }

            if (result.MonitorTaskId == "")
            {
                var value = result.Value;
                // do to
            }
        }
    }
}
